/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

#ifndef LEVELMASTER2000_H
#define LEVELMASTER2000_H

//TODO: use tr(STRING) for all hardcoded strings in method calls.
//TODO: refactor all signals prefix sig

//NOTE: in case valueChanged doesn't get called for some new property type,
//check and see the qtpropertymanager.cpp (constructor of new class) and
//see to which signals it connects. QPointF is fixed, just comare it,
//mainly it'll be something like
//connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double, double)),
//            this, SLOT(slotDoubleChanged(QtProperty *, double)));
//the third double of the signal...

#include "ui_levelmaster2000.h"

#include <QCompleter>
#include <QDebug>
#include <QDomDocument>

#include <QtCore/QMap>
#include <QtGui/QMainWindow>

#include "ClassInfo.h"
#include "Communicator.h"
#include "ComponentBrowser.h"
#include "Entity.h"
#include "EntityExplorer.h"
#include "LevelManager.h"
#include "PropertyBrowser.h"

#include "widgets/ComponentTreeWidgetItem.h"
#include "widgets/EntityTreeWidgetItem.h"
#include "widgets/GroupTreeWidgetItem.h"

class QAction;
class QDialog;
class QDockWidget;
class QLineEdit;
class QMenu;
class QTextEdit;
class QTreeWidgetItem;
class QTreeWidget;
class QUndoStack;
class QUndoView;
class QWebView;

class LevelMaster2000 : public QMainWindow
{
    Q_OBJECT

public:
    LevelMaster2000( QWidget *parent = 0, Qt::WFlags flags = 0 );
    ~LevelMaster2000();

    static int DISALLOW_NEW_COMMAND;

    //To JavaScript exposed properties:
    Q_PROPERTY( QString data READ getCommandXmlData WRITE setCommandXmlData );

public slots:
    //To JavaScript exposed slots (accessible as methods):
    //Note: don't use this. This is for javascript only. Use Logger::addLogMessage instead.
    void addLogMessage( QString level, QString loggerName, QString message );

private slots:

    void showComponentBrowser( bool show );
    void onLoadedSceneHierarchy( QList<IPBObject*> pbObjects );
    void onComponentInfo( QList<ClassInfo> componentInfo );
    void toggleLiveMode( bool isChecked );

    //Methods:
private:
    //Common:
    void initCommonStuff();
    void initCommunicator();
    void initComponentBrowser( QList<ClassInfo> &componentInfo );
    void initEntityExplorer();
    void initPropertyBrowser();
    void initUndoView();
    void initSettings();
    void initLevelManager();

    void createActions();
    void createMenus();

    //Get and set for data property, which communicates with JavaScript:
    QString getCommandXmlData();
    void setCommandXmlData( QString xml );

private:
    //Level Actions:
    QAction *saveCurrentLevelAction;
    QAction *showLevelManagerAction;
    QAction *setWorkspaceAction;

    //Other Actions:
    QAction *undoAction;
    QAction *redoAction;
    QAction *exitAction;

    //Window Actions:
    QAction *showComponentBrowserAction;
    QAction *showEntityExplorerAction;
    QAction *showLogViewAction;
    QAction *showPropertyBrowserAction;

    //Menus:
    QMenu *fileMenu;
    QMenu *projectMenu;
    QMenu *editMenu;
    QMenu *windowMenu;
    QMenu *helpMenu;

    //Common:
    Ui::LevelMaster2000Class ui;
    QDomDocument domDocument;
    QString xmlDataString;

    QUndoStack  *undoStack;
    QUndoView   *undoView;

    Communicator        *communicator;
    ComponentBrowser    *componentBrowser;
    EntityExplorer      *entityExplorer;
    LevelManager        *levelManager;
    PropertyBrowser     *propertyBrowser;
    QWebView            *scene;
};

#endif 
